package com.czxy.controller;

import com.czxy.pojo.News;
import com.czxy.service.NewsService;
import com.czxy.vo.NewsResult;
import com.czxy.vo.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @author 张青卯
 */
@RestController
@RequestMapping
public class NewsController {

    private final NewsService newsService;

    @Autowired
    public NewsController(NewsService newsService) {
        this.newsService = newsService;
    }

    @GetMapping("/news")
    public ResponseEntity<Object> findNews(PageRequest pageRequest){
        List<News> newsList = newsService.findNewsByPage(pageRequest);
        int count = newsService.findTotalCount();
        NewsResult result = new NewsResult(0, "成功", count, newsList);
        return ResponseEntity.ok(result);
    }
}
